package cn.myschool.test.day5;

import cn.myschool.dao.GradeDao;
import cn.myschool.dao.SubjectDao;
import cn.myschool.entity.Grade;
import cn.myschool.entity.Subject;
import cn.myschool.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * @author oldliu
 * @since 1.0
 */
public class SessionRollBAck {
    public static void main(String[] args) {
        SqlSession s= MybatisUtil.get();
        try {
            GradeDao g=s.getMapper(GradeDao.class);
            Grade grade=new Grade();
            grade.setGname("幼儿园大班");
            g.add(grade);
            SubjectDao sdao=s.getMapper(SubjectDao.class);
            Subject sub=new Subject();
            sub.setClasshour(12);
            sub.setGradeid(grade.getId());
            sub.setSubjectname("java oop");
            sdao.add(sub);
        } catch (Exception e) {
            e.printStackTrace();
            s.rollback();
        }

        MybatisUtil.close(s);
    }
}
